export const getTreeData = parentKey => {
  const level = (parentKey ? parentKey.split('-').length : 0) + 1;
  if (level > 3) return [];
  const lengthMap = {
    1: 300,
    2: 3000,
    3: 1000
  };
  return new Array(lengthMap[level]).fill(0).map((item, index) => ({
    title: `item ${index}`,
    key: `${parentKey ? parentKey + '-' : ''}${index}}`,
    children: getTreeData(`${parentKey ? parentKey + '-' : ''}${index}`)
  }));
};

export const getTreeDataApi = () => {
  return new Promise(resolve => {
    resolve(getTreeData())
  });
}

export const getTreeDataAsync = (length, parentKey) => {
  const level = (parentKey ? parentKey.split('-').length : 0) + 1;
  return new Promise(resolve => {
    resolve(new Array(length).fill(0).map((item, index) => ({
      title: `item ${index}`,
      key: `${parentKey ? parentKey + '-' : ''}${index}`,
      parentKey,
      level,
      isLeaf: level === 3
    })))
  });
}